﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using CommerceOne.Domains.Commons;
using CommerceOne.Domains.Repositories;
using CommerceOne.Domains.Services;
using CommerceOne.Domains.SqlRepositories;
using CommerceOne.Models;
using CommerceOne.Widgets.PagingAndSortingNav;

namespace CommerceOne.Controllers
{
    public class HomeController : ControllerBase
    {
        private readonly IProductRepository _productRepository = new SqlProductRepository();

        /// <summary>
        /// Indexes the specified page number.
        /// </summary>
        /// <param name="pageNumber">The page number.</param>
        /// <returns></returns>
        public ActionResult Index()
        {
            HomeViewModel viewModel = new HomeViewModel();
            this.CommonInitialize(viewModel);

            int size = 10;
            int totalRecord = this._productRepository.GetTotalItem();

            PagingSortingNavController pagingSortingController = new PagingSortingNavController();
            viewModel.PagingSortingViewModel = pagingSortingController.GetViewModel(totalRecord, size, 1, "/{0}");
            
            //int skip = (pageNumber - 1) * size;
            viewModel.NewestProductList = this._productRepository.GetAll().OrderBy(p=>p.AvailableDay).Take(size).ToList();

            ////IFilterParam brandParam = new FilterParam<int>("ProductSearchView", "BrandId", FilterType.Equal, 6);
            ////IFilterParam categoryParam = new FilterParam<int>("ProductSearchView", "CategoryId", FilterType.Equal, 1);
            ////List<IFilterParam> filterList = new List<IFilterParam>(new IFilterParam[] { brandParam, categoryParam });

            ////ISearchService searchService = new SearchService();
            ////SearchProductResult searchResult = searchService.SearchProduct(string.Empty, filterList);
            
            return View(viewModel);
        }
    }
}
